<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="ID" prop="virusId">
        <el-input
          v-model="queryParams.virusId"
          placeholder="请输入ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发生时间" prop="time">
        <el-input
          v-model="queryParams.time"
          placeholder="请输入发生时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构代码" prop="institutionCode">
        <el-input
          v-model="queryParams.institutionCode"
          placeholder="请输入机构代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构简称" prop="institutionShort">
        <el-input
          v-model="queryParams.institutionShort"
          placeholder="请输入机构简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分支机构名称" prop="institutionBranch">
        <el-input
          v-model="queryParams.institutionBranch"
          placeholder="请输入分支机构名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构所属地区" prop="institutionBranchArea">
        <el-input
          v-model="queryParams.institutionBranchArea"
          placeholder="请输入机构所属地区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="感染设备IP" prop="deviceAddress">
        <el-input
          v-model="queryParams.deviceAddress"
          placeholder="请输入感染设备IP"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="感染设备的主机名" prop="deviceName">
        <el-input
          v-model="queryParams.deviceName"
          placeholder="请输入感染设备的主机名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="病毒哈希值" prop="virusHashcode">
        <el-input
          v-model="queryParams.virusHashcode"
          placeholder="请输入病毒哈希值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="哈希算法" prop="hashName">
        <el-input
          v-model="queryParams.hashName"
          placeholder="请输入哈希算法"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="病毒名称" prop="virusName">
        <el-input
          v-model="queryParams.virusName"
          placeholder="请输入病毒名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="防病毒产品" prop="antiVirusProduct">
        <el-input
          v-model="queryParams.antiVirusProduct"
          placeholder="请输入防病毒产品"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处置状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入处置状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="病毒统一哈希值" prop="virusUnifyHashcode">
        <el-input
          v-model="queryParams.virusUnifyHashcode"
          placeholder="请输入病毒统一哈希值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:virus:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:virus:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:virus:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:virus:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="virusList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="virusId" />
      <el-table-column label="发生时间" align="center" prop="time" />
      <el-table-column label="机构代码" align="center" prop="institutionCode" />
      <el-table-column label="机构简称" align="center" prop="institutionShort" />
      <el-table-column label="分支机构名称" align="center" prop="institutionBranch" />
      <el-table-column label="机构所属地区" align="center" prop="institutionBranchArea" />
      <el-table-column label="感染设备IP" align="center" prop="deviceAddress" />
      <el-table-column label="感染设备的主机名" align="center" prop="deviceName" />
      <el-table-column label="病毒哈希值" align="center" prop="virusHashcode" />
      <el-table-column label="哈希算法" align="center" prop="hashName" />
      <el-table-column label="病毒类型" align="center" prop="virusType" />
      <el-table-column label="病毒名称" align="center" prop="virusName" />
      <el-table-column label="防病毒产品" align="center" prop="antiVirusProduct" />
      <el-table-column label="感染设备类型" align="center" prop="deviceType" />
      <el-table-column label="处置状态" align="center" prop="state" />
      <el-table-column label="病毒统一哈希值" align="center" prop="virusUnifyHashcode" />
      <el-table-column label="推送状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:virus:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:virus:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改病毒感染表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="发生时间" prop="time">
          <el-input v-model="form.time" placeholder="请输入发生时间" />
        </el-form-item>
        <el-form-item label="机构代码" prop="institutionCode">
          <el-input v-model="form.institutionCode" placeholder="请输入机构代码" />
        </el-form-item>
        <el-form-item label="机构简称" prop="institutionShort">
          <el-input v-model="form.institutionShort" placeholder="请输入机构简称" />
        </el-form-item>
        <el-form-item label="分支机构名称" prop="institutionBranch">
          <el-input v-model="form.institutionBranch" placeholder="请输入分支机构名称" />
        </el-form-item>
        <el-form-item label="机构所属地区" prop="institutionBranchArea">
          <el-input v-model="form.institutionBranchArea" placeholder="请输入机构所属地区" />
        </el-form-item>
        <el-form-item label="感染设备IP" prop="deviceAddress">
          <el-input v-model="form.deviceAddress" placeholder="请输入感染设备IP" />
        </el-form-item>
        <el-form-item label="感染设备的主机名" prop="deviceName">
          <el-input v-model="form.deviceName" placeholder="请输入感染设备的主机名" />
        </el-form-item>
        <el-form-item label="病毒哈希值" prop="virusHashcode">
          <el-input v-model="form.virusHashcode" placeholder="请输入病毒哈希值" />
        </el-form-item>
        <el-form-item label="哈希算法" prop="hashName">
          <el-input v-model="form.hashName" placeholder="请输入哈希算法" />
        </el-form-item>
        <el-form-item label="病毒名称" prop="virusName">
          <el-input v-model="form.virusName" placeholder="请输入病毒名称" />
        </el-form-item>
        <el-form-item label="防病毒产品" prop="antiVirusProduct">
          <el-input v-model="form.antiVirusProduct" placeholder="请输入防病毒产品" />
        </el-form-item>
        <el-form-item label="处置状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入处置状态" />
        </el-form-item>
        <el-form-item label="病毒统一哈希值" prop="virusUnifyHashcode">
          <el-input v-model="form.virusUnifyHashcode" placeholder="请输入病毒统一哈希值" />
        </el-form-item>
        <el-form-item label="指标有效标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入指标有效标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listVirus, getVirus, delVirus, addVirus, updateVirus } from "@/api/system/virus";

export default {
  name: "Virus",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 病毒感染表表格数据
      virusList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        virusId: null,
        time: null,
        institutionCode: null,
        institutionShort: null,
        institutionBranch: null,
        institutionBranchArea: null,
        deviceAddress: null,
        deviceName: null,
        virusHashcode: null,
        hashName: null,
        virusType: null,
        virusName: null,
        antiVirusProduct: null,
        deviceType: null,
        state: null,
        virusUnifyHashcode: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询病毒感染表列表 */
    getList() {
      this.loading = true;
      listVirus(this.queryParams).then(response => {
        this.virusList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        virusId: null,
        time: null,
        institutionCode: null,
        institutionShort: null,
        institutionBranch: null,
        institutionBranchArea: null,
        deviceAddress: null,
        deviceName: null,
        virusHashcode: null,
        hashName: null,
        virusType: null,
        virusName: null,
        antiVirusProduct: null,
        deviceType: null,
        state: null,
        virusUnifyHashcode: null,
        status: null,
        createTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.virusId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加病毒感染表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const virusId = row.virusId || this.ids
      getVirus(virusId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改病毒感染表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.virusId != null) {
            updateVirus(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVirus(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const virusIds = row.virusId || this.ids;
      this.$modal.confirm('是否确认删除病毒感染表编号为"' + virusIds + '"的数据项？').then(function() {
        return delVirus(virusIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/virus/export', {
        ...this.queryParams
      }, `virus_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
